<template>
	<view class="w-1 p-r-30">
		<up-search placeholder="请输入搜索内容" @search="getSearch" @custom="getSearch" borderColor="#f6f6f6" v-model="keyword"
			focus height="68rpx" :actionStyle="actionStyle" searchIconSize="45rpx"></up-search>
		<view class="w-1 fr-b-c m-t-30" v-if="hislist.length">
			<text class="c-00 fs-28 bold">历史搜索</text>
			<view class="fr-s-c" style="color: #676767;">
				<up-icon name="trash" size="45rpx" color="#676767" @click="clearHistory"></up-icon>
				<!-- <text class="fs-24 m-l-10">清空记录</text> -->
			</view>
		</view>
		<view class="w-1  fr-s-s warp" v-if="hislist.length">
			<view v-for="(item,index) in hislist" :key="index" class="fr-c his-label fs-28 m-t-20 m-r-20">
				<!-- <up-icon name="clock"></up-icon> -->
				<text @click="valSearch(item)" class="text-line-1 c-33 fs-22">{{item}}</text>
				<!-- <up-icon name="close" @click="delone(index)"></up-icon> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				path: this.$path,
				hislist: [],
				keyword: '',
				type: 0,
				curtab: 0,
				actionStyle: {
					width: '140rpx',
					height: '68rpx',
					background: '#01796d',
					borderRadius: '34rpx',
					textAlign: 'center',
					lineHeight: '68rpx',
					color: '#fff',
					fontSize: '28rpx'
				},
				hots: []
			}
		},
		onLoad(o) {
			this.curtab = o.curtab || 0;
			this.type = o.type || 0;
			this.hislist = uni.getStorageSync('hislista') || [];
		},
		onShow() {
			this.hislist = uni.getStorageSync('hislista') || [];
		},
		methods: {
			// 搜索
			getSearch(val) {
				this.keyword = val;
				if (this.keyword.trim().length > 0) {
					this.hislist.unshift(this.keyword)
					this.hislist = [...new Set(this.hislist)]
					uni.setStorageSync('hislista', this.hislist)
					uni.navigateTo({
						url: './Searchs?keyword=' + this.keyword
					})
				} else {
					this.$u.toast('请输入要搜索的内容');
				}
			},
			// 点击记录搜索
			valSearch(item) {
				this.keyword = item;
				let hislist = JSON.parse(JSON.stringify(this.hislist));
				hislist.unshift(item);
				this.hislist = [...new Set(hislist)]
				uni.setStorageSync('hislista', this.hislist)
				uni.navigateTo({
					url: './Searchs?keyword=' + this.keyword
				})
			},
			// 清空历史记录
			clearHistory() {
				this.hislist = []
				uni.setStorageSync('hislista', this.hislist)
			},
			delone(index){
				this.hislist.splice(index,1);
				uni.setStorageSync('hislista', this.hislist)
			}
		}
	}
</script>

<style>
	page {
		background: #ffffff;
	}

	.o-box {
		width: 690rpx;
		height: 72rpx;
		background: #DDDDDD;
		border-radius: 96rpx 96rpx 96rpx 96rpx;
		opacity: 1;
	}



	.his-label {
		min-width: 122rpx;
		padding: 8rpx 20rpx;
		/* height: 46rpx; */
		opacity: 1;
		border-radius: 24rpx;
		background: #f3f3f3;
	}
</style>